import { apiGet, apiPost, apiPut, apiDelete } from './client'

export interface Clazz {
  id?: number
  majorId?: number
  name?: string
  gradeYear?: number
}

type BoPage<T> = { pageNum: number; pageSize: number; total: number; pages: number; list: T[] }

export async function listClasses(params: { majorId?: number; gradeYear?: number; keyword?: string; pageNum: number; pageSize: number }) {
  const page = await apiGet<BoPage<Clazz>>('/api/grades/classes/page', params)
  return { items: page.list || [], total: page.total || 0 }
}

export async function getClass(id: number) {
  return apiGet<Clazz>(`/api/grades/classes/${id}`)
}

export async function createClass(clazz: Clazz) {
  return apiPost<Clazz>('/api/grades/classes', clazz)
}

export async function updateClass(id: number, clazz: Clazz) {
  return apiPut<Clazz>(`/api/grades/classes/${id}`, clazz)
}

export async function deleteClass(id: number) {
  return apiDelete<string>(`/api/grades/classes/${id}`)
}